#include "logAndCreat.hpp"

int main()
{
    int fd = open(FIFO_FILE, O_WRONLY);
    //创建相同的key
    key_t key = CreateKey();
    log() << "key:" << key << endl;
    //获取共享内存
    int shmid = shmget(key, MEM_SIZE, IPC_CREAT);
    if (shmid < 0)
    {
        log() << "shmget:" << strerror(errno) << endl;
        return 2;
    }

    //将共享内存和自己的进程产生关联attach
    char *str = (char *)shmat(shmid, nullptr, 0);

    while (1)
    {
        printf("please enter#");
        fflush(stdout);
        ssize_t s = read(0, str, MEM_SIZE); //将从键盘信息写入共享内存
        if (s > 0)
            str[s] = '\0';

        //将信息写入命名管道，让server得知写入完毕
        uint32_t cmd = 1;
        write(fd, &cmd, sizeof(cmd));
    }

    //去关联
    shmdt(str);
    return 0;
}
